package com.kkb.session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet("/save")
public class SaveSessionServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        HttpSession session = request.getSession();
        session.setAttribute("name1","value1");

        Cookie cookie = new Cookie("JSESSIONID",session.getId());
        cookie.setPath(request.getContextPath());
        cookie.setMaxAge(60 * 10);
        response.addCookie(cookie);
        response.getWriter().print(session.getAttribute("name1"));
    }
}
